class Car
{
  int posX,posY;
  int rectWidth,rectHeight,wheelPosX,wheelPosY;
  color rectColor;  
  color origColor;
  
  Car (int x1, int y1, int width1, int height1, color color1){
  posX=x1;
  posY=y1;
  rectWidth=width1;
  rectHeight=height1;
  rectColor=color1;
  origColor=color1;
  }
  
  void draw(){ 
  checkPos();  
  drawWheel();
  drawCarShape();
  drawWindows();
  }
  
  void cambiarBrillo()
  {  
  rectColor = color(  hue(rectColor),
                      saturation(rectColor),
                      brightness(rectColor)+80
                      ); 
  }
  
  void reiniciarColor()
  {
  rectColor = origColor;
  }
  
  boolean isMouseIn(int mX,int mY){
  boolean mouseIn;  
  if(mX>posX && mX< (posX+rectWidth))
  {
    if(mY>posY && mY<(posY+rectHeight))
    mouseIn = true;
    else
    mouseIn = false;    
  }  
  else
  mouseIn = false;
  //println(mouseIn);
return mouseIn;
}

void drawCarShape(){
  pushStyle();
  fill(rectColor);
  beginShape();
  vertex(2*rectWidth/7+posX, posY);
  vertex(5*rectWidth/7+posX, posY);
  vertex(6*rectWidth/7+posX, posY+2*rectHeight/6);
  vertex(7*rectWidth/7+posX, posY+2*rectHeight/6);
  vertex(7*rectWidth/7+posX, posY+4*rectHeight/6);
  vertex(0*rectWidth/7+posX, posY+4*rectHeight/6);
  vertex(0*rectWidth/7+posX, posY+2*rectHeight/6);
  vertex(1*rectWidth/7+posX, posY+2*rectHeight/6);
  endShape(CLOSE);
  popStyle();
} 

void drawWheel(){
  pushStyle();
  fill(#000000);
  ellipse(posX+2*rectWidth/7,posY+4*rectHeight/6, (rectHeight/6)*2.5, (rectHeight/6)*2.5);
  ellipse(posX+5*rectWidth/7,posY+4*rectHeight/6, (rectHeight/6)*2.5, (rectHeight/6)*2.5);
  popStyle();
}

void drawWindows(){
  pushStyle();
  fill(#CCFFFF);
  beginShape();
  vertex(4.5*rectWidth/14+posX, rectHeight/12+posY);
  vertex(9.5*rectWidth/14+posX, rectHeight/12+posY);
  vertex(11*rectWidth/14+posX, 4*rectHeight/12+posY);
  vertex(3*rectWidth/14+posX, 4*rectHeight/12+posY);
  endShape(CLOSE);
  popStyle();
}

void moveCar(int mX, int mY){
posX=mX-rectWidth/2;
posY=mY-rectHeight/2;
}

  void moveCarHor(int mX){
    posX=mX-rectWidth/2;
  }

  void checkPos(){
  if(posX<=0)
  posX=0;
  if(posX>=myWidth-rectWidth)
  posX=myWidth-rectWidth;
  if(posY<=0)
  posY=0;
  if(posY>=myHeight-(5*rectHeight/6))
  posY=myHeight-(5*rectHeight/6);
  }
}


